package com.ist.viewpagerhelper.adpter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by zhengshaorui on 2017/10/18.
 */

public class FpagerAdapter extends PagerAdapter {
    private List<View> mViews;
    private List<String> mTitles;
    public FpagerAdapter(List<View> views, List<String> titles) {
        this.mViews = views;
        this.mTitles = titles;
    }

    @Override
    public int getCount() {
        return mViews == null ? 0 :mViews.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        //return super.instantiateItem(container, position);
        View view = mViews.get(position);
        container.addView(view);
        return view;

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //super.destroyItem(container, position, object);
        container.removeView(mViews.get(position));

    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles == null?super.getPageTitle(position):mTitles.get(position);
    }
}
